#include <gtest/gtest.h>
#include "../stdlib/radixsort.h"

#define SIZ 5
#define SZ 13
char *tobesort[SZ] = {"bb", "cd", "ab", "ef", "ac", "dg", "kd", "ba", "na", "jk", "wo", "me", "suck"};
char *aa[SZ] = {"bb","cd", "ab", "ef", "ac", "dg", "kd", "ba", "na", "jk", "wo", "me", "suck"};

TEST(RADIXSORTTEST, SIMPLE) {

  const u_char *tr;
  int c;
  u_char tr0[256];

  int endch = 0;
  tr = tr0;
  for (c = 0; c < endch; c++)
    tr0[c] = c + 1;
  tr0[c] = 0;
  for (c++; c < 256; c++)
    tr0[c] = c;
  endch = 0;
  
  simplesort((const u_char **)tobesort, SIZ, 0, tr, endch);

  EXPECT_STREQ("ab", tobesort[0]);
  EXPECT_STREQ("ac", tobesort[1]);
  EXPECT_STREQ("bb", tobesort[2]);
  EXPECT_STREQ("ef", tobesort[4]);
  EXPECT_STREQ("suck", tobesort[12]);
  EXPECT_STREQ("wo", tobesort[10]);
}

TEST(RADIXSORTTEST, RADIX) {

  radixsort((const u_char **)aa, NULL, SZ, 0);


  EXPECT_STREQ("ab", tobesort[0]);
  EXPECT_STREQ("ac", tobesort[1]);
  EXPECT_STREQ("bb", tobesort[2]);
  EXPECT_STREQ("ef", tobesort[4]);
  EXPECT_STREQ("suck", tobesort[12]);
  EXPECT_STREQ("wo", tobesort[10]);

}
